package mylab.commons.web.mvc.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import mylab.base.model.entity.LongIdEntity;
import mylab.starters.mybatis.utils.MpUtils;
import mylab.utils.common.ReflectUtil;


@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public abstract class BaseNestedEntity<T extends BaseEntity> extends BaseEntity {

    @TableField(exist = false)
    protected Class<T> entityClass;

    protected BaseMapper<T> getMapper() {
        return MpUtils.getMapper(getEntityClass());
    }

    protected Class<T> getEntityClass() {
        if (entityClass == null) {
            this.entityClass = ReflectUtil.getGenericType(this.getClass(), 0);
        }
        return entityClass;
    }
}
